/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistence;

import core.AEntityContentProvider;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Set;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Ivan
 */
@Entity
@Table(name = "GAME")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Game.findAll", query = "SELECT g FROM Game g"),
    @NamedQuery(name = "Game.findByGameId", query = "SELECT g FROM Game g WHERE g.gameId = :gameId"),
    @NamedQuery(name = "Game.findByStatus", query = "SELECT g FROM Game g WHERE g.status = :status"),
    @NamedQuery(name = "Game.findByVenue", query = "SELECT g FROM Game g WHERE g.venue = :venue"),
    @NamedQuery(name = "Game.findByDateOfCompetition", query = "SELECT g FROM Game g WHERE g.dateOfCompetition = :dateOfCompetition"),
    @NamedQuery(name = "Game.findByScore", query = "SELECT g FROM Game g WHERE g.score = :score")})
public class Game  extends AEntityContentProvider<Game> implements Serializable  {
    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Id
    //@Basic(optional = false)
    //@NotNull
    @GeneratedValue(generator="CommonSeq", strategy= GenerationType.SEQUENCE)
    @SequenceGenerator( name="CommonSeq",sequenceName="common_seq", initialValue=1 , allocationSize=1)
    @Column(name = "GAME_ID")
    private BigDecimal gameId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 15)
    @Column(name = "STATUS")
    private String status;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 25)
    @Column(name = "VENUE")
    private String venue;
    @Basic(optional = false)
    @NotNull
    @Column(name = "DATE_OF_COMPETITION")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateOfCompetition;
    @Size(max = 10)
    @Column(name = "SCORE")
    private String score;
    @OneToMany(mappedBy = "gameId")
    private Set<GameContract> gameContractSet;
    @JoinColumn(name = "TOURNAMENT_ID", referencedColumnName = "TOURNAMENT_ID")
    @ManyToOne
    private Tournament tournamentId;
    @JoinColumn(name = "WINNER_TEAM_ID", referencedColumnName = "TEAM_ID")
    @ManyToOne
    private Team winnerTeamId;
    @JoinColumn(name = "OWNER", referencedColumnName = "SYS_USER_ID")
    @ManyToOne(optional = false)
    private SysUser owner;
    @JoinColumn(name = "PLAYER_ID", referencedColumnName = "PLAYER_ID")
    @ManyToOne
    private Player playerId;

    public Game() {
        
    }

   
    
    public Game(BigDecimal gameId) {
        super(Game.class);
        this.gameId = gameId;
    }

    public Game(BigDecimal gameId, String status, String venue, Date dateOfCompetition) throws Exception{
        super(Game.class);
        this.gameId = gameId;
        this.status = status;
        this.venue = venue;
        this.dateOfCompetition = dateOfCompetition;
        
    }

    public BigDecimal getGameId() {
        return gameId;
    }

    public void setGameId(BigDecimal gameId) {
        this.gameId = gameId;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getVenue() {
        return venue;
    }

    public void setVenue(String venue) {
        this.venue = venue;
    }

    public Date getDateOfCompetition() {
        return dateOfCompetition;
    }

    public void setDateOfCompetition(Date dateOfCompetition) {
        this.dateOfCompetition = dateOfCompetition;
    }

    public String getScore() {
        return score;
    }

    public void setScore(String score) {
        this.score = score;
    }

    @XmlTransient
    public Set<GameContract> getGameContractSet() {
        return gameContractSet;
    }

    public void setGameContractSet(Set<GameContract> gameContractSet) {
        this.gameContractSet = gameContractSet;
    }

    public Tournament getTournamentId() {
        return tournamentId;
    }

    public void setTournamentId(Tournament tournamentId) {
        this.tournamentId = tournamentId;
    }

    public Team getWinnerTeamId() {
        return winnerTeamId;
    }

    public void setWinnerTeamId(Team winnerTeamId) {
        this.winnerTeamId = winnerTeamId;
    }

    public SysUser getOwner() {
        return owner;
    }

    public void setOwner(SysUser owner) {
        this.owner = owner;
    }

    public Player getPlayerId() {
        return playerId;
    }

    public void setPlayerId(Player playerId) {
        this.playerId = playerId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (gameId != null ? gameId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Game)) {
            return false;
        }
        Game other = (Game) object;
        if ((this.gameId == null && other.gameId != null) || (this.gameId != null && !this.gameId.equals(other.gameId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "persistence.Game[ gameId=" + gameId + " ]";
    }
    
}
